package com.coninbell.ssbresources;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

/**
 *
 * @author wadjakman
 */
public class Auth
{

  public static boolean login(String username, String password) 
  {
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    Key key = KeyFactory.createKey("user", username);
    
    try
    {
      Entity user = datastore.get(key);
      String entPassword = (String) user.getProperty("password");
      if (password.equals(entPassword))
        return true;
      else
        return false;
    }
    catch (EntityNotFoundException ex)
    {
      return false;
    }
  }
}
